package com.system.business.controller;


import cn.hutool.core.bean.BeanUtil;
import com.system.business.domain.Train;
import com.system.business.req.ConfirmOrderQueryReq;
import com.system.business.req.ConfirmOrderSaveReq;
import com.system.business.req.TrainQueryReq;
import com.system.business.req.TrainSaveReq;
import com.system.business.resp.ConfirmOrderQueryResp;
import com.system.business.resp.TrainQueryResp;
import com.system.business.service.TrainService;
import com.system.common.resp.CommonResp;
import com.system.common.resp.PageResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/train")
public class TrainController {

    @Autowired
    private TrainService trainService;
    @PostMapping("/save")
    public CommonResp<Object> save(@Valid @RequestBody TrainSaveReq req) {
        trainService.save(req);
        return new CommonResp<>();
    }

    @GetMapping("/query-list")
    public CommonResp<PageResp<TrainQueryResp>> queryList(@Valid TrainQueryReq req) {
        PageResp<TrainQueryResp> list = trainService.queryList(req);
        return new CommonResp<>(list);
    }

    @GetMapping("/query-all")
    public CommonResp<List<TrainQueryResp>> queryList() {
        List<Train> trains = trainService.list();
        List<TrainQueryResp> list = BeanUtil.copyToList(trains, TrainQueryResp.class);
        return new CommonResp<>(list);
    }
}
